class Admin::BatchesController < ApplicationController

  uses_tiny_mce(:options => { :theme => "advanced",
                              :width => "100%",
                              :plugins => %w{advimage preview},
                              :theme_advanced_buttons1 => "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,insertfile,insertimage,cleanup,|,code,preview",
                              :theme_advanced_buttons2 => "",
                              :theme_advanced_toolbar_location => "top",
                              :theme_advanced_toolbar_align => "left",
                              :theme_advanced_statusbar_location => "bottom"
                            })
  
  def index
    @batches = Batch.find_all_by_parent_batch_id(0)
  end
  
    
  def show
    if !params[:id].nil?
      @batch = Batch.find(params[:id])
    else
      flash[:error] = "Not Found "
    end
  end
  
  def new
    @batch = Batch.new
  end
  
  def create
    if !params[:batch].nil?
      @batch = Batch.new(params[:batch])
      if @batch.save
        flash[:notice] = "New batch - #{@batch.name} has been created "
      else
        flash[:notice] = "Failed to create #{@batch.name} "
        render :action=>"new"
      end
    end
    redirect_to :action=>"show", :id => @batch.id
  end
  
  def edit
    if !params[:id].nil?
      @batch = Batch.find(params[:id])
    else
      flash[:error] = "No batch to edit"
      redirect_to :action=>'index'
    end
  end
  
  def update
    if !params[:batch].nil?
      @batch = Batch.find(params[:id])
      if @batch.update_attributes(params[:batch])
        flash[:notice] = "Batch: #{@batch.name} has been updated"
        redirect_to :action=>'show', :id=>@batch.id
      else
        flash[:error] = "Could not update Batch: #{@batch.name} "
      end
    end
  end

  
end
